package com.zspringboot.demo.controller;




import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import com.zspringboot.demo.common.Result;

import java.util.List;
import com.zspringboot.demo.service.INetEffectService;
import com.zspringboot.demo.entity.NetEffect;



import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 周结果  完成/未完成 前端控制器
 * </p>
 *
 * @author laolang
 * @since 2024-03-12
 */
@RestController
@RequestMapping("/net-effect")
public class NetEffectController {


    @Resource
    private INetEffectService netEffectService;

    // 新增/修改
    @PostMapping
    public Result save(@RequestBody NetEffect netEffect) {
            return Result.success(netEffectService.saveOrUpdate(netEffect));
            }

    // 删除
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
            return Result.success(netEffectService.removeById(id));
            }
    // 批量删除
    @PostMapping("/del/batch")
    public Result deleteBacth(@RequestBody List<Integer> ids){
        return Result.success(netEffectService.removeByIds(ids));
        }
    // 查询所有数据
    @GetMapping
    public Result findAll() {
            return Result.success(netEffectService.list());
            }

    // 根据id 查询
    @GetMapping("/{id}")
    public Result findOne(@PathVariable Integer id) {
            return Result.success(netEffectService.getById(id));
            }

    // 分页
    @GetMapping("/page")
    public Result findPage(@RequestParam Integer pageNum,
                            @RequestParam Integer pageSize,
                            @RequestParam(defaultValue = "") String userId) {
            QueryWrapper<NetEffect> queryWrapper = new QueryWrapper<>();

            if (!"".equals(userId))
            queryWrapper.eq("user_id",userId).or();
            queryWrapper.eq("user_id",0);
            return Result.success(netEffectService.page(new Page<>(pageNum, pageSize),queryWrapper));
            }

}

